﻿Converse by Sir Gareth begins here.

Section 1 - Kinds

A choice is a kind of thing.
  A choice can be active.  A choice is usually active.
  A choice can be repeatable.  A choice is usually not repeatable.
  A choice has a number called selection-number.
  A choice has a property called text-description.
  The description of a choice is usually "".


A node is a kind of thing.  The initial appearance of a node is usually "".

The end-node is a node.

A person has a property called end-message.  The end-message of a person is usually "'Goodbye.'".
A person has a property called no-talk-message.  The no-talk-message of a person is usually "You can't think of anything to say."
A person has a property called beginning-message.  The beginning-message of a person is usually "'Hello.'"

[The player has a property called initial-node.]

A person can be in-conversation.
A person can be temporarily-choosing.
[The player has a property called current-node.
The player has a property called current-speaker.]

The current-speaker is a person that varies

The current-node is a node that varies

Section 2 - Relations

Initiating relates one node (called the initial-node) to one person.  The verb to initiate (it initiates, they initiates, it initiated, it is initiated) implies the initiating relation.

Offering relates one node (called the choice-node) to various choices.  The verb to offer (it offers, they offer, it offered, it is offered) implies the offering relation.

Node-following relates one node (called the following-node) to various choices.  The verb to node-follow (it node-follows, they node-follow, it node-followed, it is node-followed) implies the node-following relation.

Speaking relates one person (called the speaker) to various nodes.  The verb to speak (it speaks, they speak, it spoke, it is spoken) implies the speaking relation.

choice-following relates one choice (called the following-choice) to various choices.  The verb to choice-follow (it choice-follows, they choice-follow, it choice-followed, it is choice-followed) implies the choice-following relation.

Section 3 - Actions

To say the current choices:
  Let N be the current-node;
  Let i be 0;
  Repeat with C running through the active choices offered by N begin;
    Change i to i plus 1;
    Change the selection-number of C to i;
    Say "   [selection-number of C] - [italic type][initial appearance of C][roman type][line break]";
  End repeat;
  Say line break;
  Now the player is not temporarily-choosing;
  If i is 0, end-the-conversation;
  Now the player is in-conversation.

To reset-the-choices:
    Repeat with C running through the choices begin;
      Change the selection-number of C to 0;
   End repeat.

To bail:
  Say "That is not an available choice.";
  Say the current choices;
  Say paragraph break.

To end-the-conversation:
  Reset-the-choices;
  [Say end-message of the current-speaker;]
  If the current-speaker is visible, say "[end-message of the current-speaker][paragraph break]";
  Now the player is not in-conversation.

To jump-to (N - a node):
   If N is not spoken by a person, say "ERROR--Speaker of [N] is not defined!";
   Change the current-speaker to the speaker of N;
   Change the current-node to N;
   Now the player is in-conversation;
   Say the initial appearance of N;
   Say the current choices.


Section 4 - Verbs

Talking to is an action applying to one thing.  Understand "talk to [someone]" and "talk with [someone]" as talking to.

Instead of talking to someone who is not initiated by a node, say the no-talk-message of the noun

Check talking to someone:
    If no active choices are offered by the initial-node of the noun, say the no-talk-message of the noun instead 

Carry out talking to someone:
  Change the current-speaker to the noun;
  Say the beginning-message of the noun;
  Say paragraph break;
  Jump-to the initial-node of the noun.

Before choosing:  Now the player is temporarily-choosing.

Instead of talking to someone when the player is in-conversation:
   say "You're already talking to [the current-speaker].";
   say the current choices.

Check doing something when the player is in-conversation and the player is not temporarily-choosing: end-the-conversation.


Choice-choosing is an action applying to one thing. 

[For testing only] Understand "choice-choose [something]" as choice-choosing

Carry out choice-choosing a choice:
  Let C be the noun;
  Say the description of C;
  If C is not repeatable, now C is not active;
  If a choice (called D) choice-follows C, now D is active;
  If a node (called N) node-follows C begin;
    Change the current-node to N;
    Say the initial appearance of N;
  End if;
  Say paragraph break;
  If the current-node is the end-node, end-the-conversation;
  Otherwise say the current choices.

One-choosing is an action applying to nothing.  Understand "1" as one-choosing.

Two-choosing is an action applying to nothing.  Understand "2" as two-choosing.

Three-choosing is an action applying to nothing.  Understand "3" as three-choosing.

Four-choosing is an action applying to nothing.  Understand "4" as four-choosing.

One-choosing, two-choosing, three-choosing, and four-choosing are choosing.

[The following doesn't work due to a bug]
[Check one-choosing:
  If the selection-number of a choice (called C) is 1, try choice-choosing C instead;
  Otherwise bail instead.]

Instead of choosing when the player is not in-conversation, say "You're not talking to anyone right now!"

Check one-choosing:
  Let N be the current-node;
  Repeat with C running through the active choices offered by N begin;
    If the selection-number of C is 1, try choice-choosing C instead;
  End repeat;
  Bail instead.

Check two-choosing:
  Let N be the current-node;
  Repeat with C running through the active choices offered by N begin;
    If the selection-number of C is 2, try choice-choosing C instead;
  End repeat;
  Bail instead.

Check three-choosing:
  Let N be the current-node;
  Repeat with C running through the active choices offered by N begin;
    If the selection-number of C is 3, try choice-choosing C instead;
  End repeat;
  Bail instead.

Check four-choosing:
  Let N be the current-node;
  Repeat with C running through the active choices offered by N begin;
    If the selection-number of C is 4, try choice-choosing C instead;
  End repeat;
  Bail instead.

Converse ends here.


---- DOCUMENTATION ----

This extension allows simple menu-driven conversations.  Conversations are made up of "nodes" and conversation "choices" that are offered at each node.

A node is an abstract object representing a point in a conversation.  A node can "offer" choices.  When a conversation arrives at a specific node, the game displays all active conversation choices that are offered by the node.  Each player who can be talked to must be given an "initial-node" at which the conversation will begin.

A choice is a conversation menu option offered at a specific node.  The initial appearance of a choice is the text that appears in the menu.  The text-description is the text displayed in response to the player picking that choice.

Choices have a property called "repeatable," which signals whether the choice can be selected more than once.  Choices are usually not repeatable, meaning that when a choice is made inactive after it is selected and won't be displayed again.

A choice can lead either to a new choice or a new node.  If the choice ends the conversation, it should lead to "end-node," which is a predefined node that signals the end of a conversation.


Here is a sample game:

	"Test" by Me

	Include Converse by Sir Gareth

	Start Room is a room.  "This is a room."

	Fred is here.  "Fred is here, waiting to talk to you."  The beginning-message of Fred is "'Hi there,' Fred says."  The end-message of Fred is "Fred turns back to what he was doing."

	Fred speaks N1 and N2.  N1 initiates Fred.

	N1 is a node.  N1 offers how-are-you, nice-game, fabulous, and bye-fred.

	How-are-you is a choice.  "Hiya Fred.  How are you?".  The text-description of how-are-you is "'I'm doing well,' Fred replies.  'How are you?'".  N2 node-follows how-are-you.


	Nice-game is a choice.  "Nice game we're in here, huh?".  The text-description  of nice-game is "'A bit boring, don't you think?' Fred asks. 'I don't really have much interesting to say.'".   Fabulous choice-follows nice-game.

	Fabulous is a choice.  "Well, I think you're a fabulous conversationalist, Fred.".  The text-description of fabulous  is "'Wise guy, aren't you?' Fred says."  Fabulous is not active.

	Bye-fred is a repeatable choice.  "See ya later, Fred.".  The text-description of bye-fred is "'Take it easy.'".  End-node node-follows bye-fred.

	N2 is a node.  N2 offers doing-well and life-sucks.

	Doing-well is a choice.  "I'm doing great!".  The text-description of doing-well is "'Glad to hear it!' says Fred.".  N1 node-follows doing-well.

	Life-sucks is a choice.  "Life sucks!".  The text-description of life-sucks is "'Sorry to hear it!' says Fred.".  N1 node-follows life-sucks.